package org.csu.mypetstore.service.impl;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.persistence.AccountDao;
import org.csu.mypetstore.persistence.impl.AccountDaoImpl;
import org.csu.mypetstore.service.AccountService;

public class AccountServiceImpl implements AccountService {
    AccountDao accountDao;

    public AccountServiceImpl(){
        this.accountDao = new AccountDaoImpl();
    }

    @Override
    public Account login(String username, String password) {
        return accountDao.getAccountByUsernameAndPassword(username, password);
    }

    @Override
    public Account getAccountByUsername(String username) {
        return  accountDao.getAccountByUsername(username);
    }

    @Override
    public void updateAccount(Account account) {
        accountDao.updateAccount(account);
    }

    @Override
    public void updateSignon(String username, String password) {
        if(password != null && !password.equals("")){
            accountDao.updateSignon(username, password);
        }
    }

    @Override
    public void userRegister(Account account) {
        accountDao.insertAccount(account);
        accountDao.insertProfile(account);
        accountDao.insertSignon(account);
    }
}
